//
//  NSString+sizeWithFont.m
//  WGFGlobalHouses
//
//  Created by waiguofang on 15/5/25.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "NSString+sizeWithFont.h"

@implementation NSString (sizeWithFont)

-(CGSize)sizeWithFont:(UIFont *)font maxSize:(CGSize)maxSize;
{
    NSDictionary *attrs = @{NSFontAttributeName:font};
    
    return [self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}


#pragma mark 计算2个日期的之前的差
+(NSInteger)stringToDate:(NSString *)endDateStr withCurrentDate:(NSString *)currentStr
{
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    
    NSDate *endDate=[dateFormatter dateFromString:endDateStr];
    NSDate *currentDate = [dateFormatter dateFromString:currentStr];
    
    
    
    
    unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents *d = [calendar components:unitFlags fromDate:currentDate toDate:endDate options:0];//计算时间差
    
    
    NSInteger numb = [d day];
    if ([d day]==0) {
        numb++;
    }
    
    return numb;
}


@end
